<?php

class Catshare extends AppModel {

    var $alias = 'Catshare';
    var $name = 'Catshare';
    var $useTable = 'share_categories';
    var $hasMany = array(
        'Share' => array(
            'className' => 'Share',
            'foreignKey' => 'cat_id',
            'dependent' => true,
        )
    );

    function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
        $parameters = compact('conditions');
        $this->recursive = $recursive;
        $count = $this->find('count', array_merge($parameters, $extra));
        if (isset($extra['group'])) {
            $count = $this->getAffectedRows();
        }
        return $count;
    }

    function getListAll() {
        $data = $this->find('list', array(
                    'fields' => 'Catshare.id, Catshare.title',
                ));
        return $data;
    }

    function cacheListAll() {

        $cacheName = 'list_catshare';
        $data = $this->find('all', array(
                    'fields' => 'Catshare.id, Catshare.title, Catshare.alias',
                ));
        Cache::write($cacheName, $data, 'cat_share');
    }

    function cacheListAllToArray() {
        $cacheName = 'list_catshare_array';
        $data = $this->find('all', array(
                    'fields' => 'Catshare.id, Catshare.title, Catshare.alias',
                ));
        $arr = array();
        foreach ($data AS $row) {
            $arr[$row['Catshare']['id']] = $row['Catshare'];
        }
        Cache::write($cacheName, $arr, 'cat_share');
    }

}

?>
